//
//  Bundle+Extension.swift
//  微博Demo
//
//  Created by 花化华 on 2016/11/27.
//  Copyright © 2016年 itcast. All rights reserved.
//

import Foundation

private let oldVersionKey = "oldVersionKey"

extension Bundle {
    var nameSpace: String {
        return Bundle.main.infoDictionary!["CFBundleName"] as! String
    }
}

extension Bundle {
    class func isNewFeature() -> Bool {
        var isNew = false
        
        //获取当前版本号
        let currentVersion = Bundle.main.infoDictionary!["CFBundleShortVersionString"] as! String
        //获取老版本号
        let oldVersion = UserDefaults.standard.value(forKey: oldVersionKey) as? String
        //判断是否是新版本
        isNew = oldVersion == nil ? true : currentVersion != oldVersion!
        //将当前版本号存储
        UserDefaults.standard.setValue(currentVersion, forKey: oldVersionKey)
        
        return isNew
    }
}
